package com.minelx.table.core;

import com.minelx.table.core.series.Series;
import com.minelx.table.core.series.index.Indexes;

import java.util.function.UnaryOperator;

public interface TableProvider {
	Series<String> row(long at);

	Series<String> column(long at);

	Series<String> title();

	Indexes rowIndexes();

	Indexes columnIndexes();

	// FIXME 2021/8/25  wait for me!!!     convert to builder or factory, use getter setter
	default TableProvider mapTitle(UnaryOperator<Series<String>> mapper) {
		return new TableProvider() {
			@Override
			public Series<String> row(long at) {
				return TableProvider.this.row(at);
			}

			@Override
			public Series<String> column(long at) {
				return TableProvider.this.column(at);
			}

			@Override
			public Series<String> title() {
				return mapper.apply(TableProvider.this.title());
			}

			@Override
			public Indexes rowIndexes() {
				return TableProvider.this.rowIndexes();
			}

			@Override
			public Indexes columnIndexes() {
				return TableProvider.this.columnIndexes();
			}
		};
	}
}
